package com.shigen.demo.thread;

/**
 * 线程的创建方式
 *
 * @author shigenfu
 * @date 2022/7/10 11:12 上午
 */
class MyThread extends Thread {

  @Override
  public void run() {
    for (int i = 0; i < 100; i++) {
      if (i % 2 == 0) {
        System.out.println(i);
      }
    }
  }
}

class Window implements Runnable {

  private int ticket =100;

  Object object = new Object();

  @Override
  public void run() {
    while (true) {
      synchronized (object) {
        if (ticket > 0) {
          System.out.println(ticket + " " + Thread.currentThread().getName());
          ticket--;
        } else {
          break;
        }
      }
    }
  }
}


public class ThreadCreate {


  public static void main(String[] args) {
    // MyThread myThread = new MyThread();
    // myThread.start();

    Window window = new Window();
    Thread thread = new Thread(window);
    Thread thread1 = new Thread(window);
    Thread thread2 = new Thread(window);
    thread.start();
    thread1.start();
    thread2.start();



  }

}
